﻿using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Win32;

namespace MikroTransfer
{
    public class Licensing
    {
        DateTime GetServerDate()
        {
            //try
            //{
            //    string tarih = new DbSqlServer( Factory.GetFactory.ExecuteScaler("SELECT CAST(YEAR(GETDATE()) AS VARCHAR) + '-' +CAST(MONTH(GETDATE()) AS VARCHAR) + '-' +CAST(DAY(GETDATE()) AS VARCHAR)").ToString();
            //    string[] dizi = tarih.Split('-');
            //    if (dizi.Length > 0)
            //        return new DateTime(int.Parse(dizi[0]), int.Parse(dizi[1]), int.Parse(dizi[2]));
            //    else
            //        return DateTime.Now;
            //}
            //catch (Exception)
            //{
            //    return DateTime.Now;
            //}
            return DateTime.Now;
        }

        public bool CheckEvaluate()
        {
            try
            {
                if (Registry.ClassesRoot.OpenSubKey("Microsoft.Workflow").OpenSubKey("CLSID").GetValueNames().Length > 0)
                    if (Registry.ClassesRoot.OpenSubKey("Microsoft.Workflow").OpenSubKey("CLSID").GetValue("").ToString() == "{C511163B-37F1-45b3-826D-336F894B0144}")
                        return false;

                DateTime currentDate = GetServerDate();
                if (currentDate >= new DateTime(2011, 7, 30))
                {
                    Registry.ClassesRoot.CreateSubKey("Microsoft.Workflow").CreateSubKey("CLSID").SetValue("", "{C511163B-37F1-45b3-826D-336F894B0144}");
                    return false;
                }
                else
                {
                    Registry.ClassesRoot.CreateSubKey("Microsoft.Workflow").CreateSubKey("CLSID").SetValue("", "");
                    return true;
                }
            }
            catch (Exception)
            {
                return false;
            }
        }
    }
}
